import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/7 14:37
 * @description 状态压缩
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {1,0,2,3,4};
        solution.maxChunksToSorted(arr);
    }
    public int maxChunksToSorted(int[] arr) {
        int n = arr.length;
        int cur = 0, max = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            cur |= 1 << arr[i];
            max = Math.max(max, arr[i]);
            if (cur == (1 << (max + 1)) - 1) {
                ans++;
            }
        }
        return ans;
    }
}
